package service.vod.utlis;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import java.util.ArrayList;
import java.util.List;

public class Vod {
    static String videoId="459812710734432aa8872b24cf76bce4";//阿里云上存储视频的id

    public static void main(String[] args) throws ClientException {
        List<String> playVideoURL = Vod.getPlayVideoURL(videoId);
        for (String videoURL : playVideoURL) {
            System.out.println("PlayInfo.PlayURL = " + videoURL + "\n");
        }
        System.out.println("playAuth="+Vod.getPlayVideoAuth(videoId));
    }
    //1.根据视频id获取视频播放地址
    public static List<String> getPlayVideoURL(String videoId) throws ClientException {
        //1.初始化操作，创建DefaultAscClient对象
        DefaultAcsClient client = InitVodUtil.initVodClient("LTAI4GKRg25GXxBVqfcKm31L","m7qbbWUPXbV5ma93aDGHEiwoAL0kYY" );
        //2.创建获取视频地址的request和response
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        GetPlayInfoResponse response = new GetPlayInfoResponse();
        //3.向request对象里面设置视频id
        request.setVideoId(videoId);
        //4.调用初始化对象中的方法:传递request进行获取数据
        response= client.getAcsResponse(request);
        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
        //5.获取播放地址
        List<String> videoURL=new ArrayList<>();
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            videoURL.add(playInfo.getPlayURL());
        }
        return videoURL;
    }
    //2.根据视频id获取视频播放凭证
    public static String getPlayVideoAuth(String videoId) throws ClientException {
        //1.初始化操作，创建DefaultAscClient对象
        DefaultAcsClient client = InitVodUtil.initVodClient("LTAI4GKRg25GXxBVqfcKm31L","m7qbbWUPXbV5ma93aDGHEiwoAL0kYY" );
        //2.创建获取视频凭证的request和response
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        //3.向request对象里面设置视频id
        request.setVideoId(videoId);
        //4.调用初始化对象中的方法:传递request进行获取数据
        response = client.getAcsResponse(request);
        //返回数据
        return response.getPlayAuth();
    }
}
